{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-06-15T17:03:11.871459400Z",
     "start_time": "2024-06-15T17:03:11.866771900Z"
    }
   },
   "outputs": [],
   "source": [
    "# test log_softmax\n",
    "import torch\n",
    "logits = torch.tensor([1,2,3,4,5,6,7,8,9,10], dtype=torch.float32)"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hahah\n"
     ]
    }
   ],
   "source": [
    "print('hahah')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-06-15T17:03:13.231180800Z",
     "start_time": "2024-06-15T17:03:13.230181400Z"
    }
   },
   "id": "1fa10edfde3e8eee",
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.])\n",
      "tensor([7.8013e-05, 2.1206e-04, 5.7645e-04, 1.5669e-03, 4.2594e-03, 1.1578e-02,\n",
      "        3.1473e-02, 8.5552e-02, 2.3255e-01, 6.3215e-01])\n",
      "tensor(1.0000)\n",
      "tensor([-9.4586, -8.4586, -7.4586, -6.4586, -5.4586, -4.4586, -3.4586, -2.4586,\n",
      "        -1.4586, -0.4586])\n",
      "tensor(-49.5863)\n",
      "tensor([7.8013e-05, 2.1206e-04, 5.7645e-04, 1.5669e-03, 4.2594e-03, 1.1578e-02,\n",
      "        3.1473e-02, 8.5552e-02, 2.3255e-01, 6.3215e-01])\n"
     ]
    }
   ],
   "source": [
    "logits = torch.tensor([1,2,3,4,5,6,7,8,9,10], dtype=torch.float32)\n",
    "print(logits)\n",
    "logits1 = logits.softmax(dim=-1)\n",
    "print(logits1)\n",
    "print(torch.sum(logits1))\n",
    "logits2 = logits.log_softmax(dim=-1)\n",
    "print(logits2)\n",
    "print(torch.sum(logits2))\n",
    "print(logits2.softmax(dim=-1))\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-06-15T17:11:33.365667600Z",
     "start_time": "2024-06-15T17:11:33.360071300Z"
    }
   },
   "id": "e9d951f373ae1f12",
   "execution_count": 16
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[-9.8886e-01, -5.5200e-01,  7.6480e-01,  1.0349e+00,  6.3640e-01,\n",
      "         -6.4676e-01, -1.5199e+00,  2.0668e-01,  1.2092e+00,  2.5186e-01,\n",
      "         -3.6805e-01, -1.2002e+00, -1.0700e+00, -1.6607e-01,  7.1148e-01,\n",
      "          1.1004e-01, -1.5158e-01, -9.2111e-01,  9.1546e-01, -8.3936e-01,\n",
      "         -1.1970e+00, -1.1236e+00,  4.4955e-02, -1.4279e+00, -1.1891e+00,\n",
      "         -1.1237e-01,  6.1381e-01,  3.7451e-02,  1.0997e+00, -7.4347e-01,\n",
      "         -1.3274e+00, -1.0941e+00, -8.4112e-01,  1.0980e+00,  1.4614e+00,\n",
      "         -2.4718e-01,  3.1140e-01, -9.1729e-01,  1.1154e+00,  1.6401e-01,\n",
      "          1.0201e+00, -9.4947e-01, -2.5914e-01,  5.0109e-01, -8.3732e-01,\n",
      "         -3.7974e-04,  6.9692e-01, -1.7509e+00,  3.9280e-01, -1.3785e+00,\n",
      "         -6.1521e-02, -1.6728e+00,  1.2317e+00, -1.9230e-01,  2.4249e+00,\n",
      "          7.6673e-01,  1.5420e-01,  4.3263e-01, -1.3904e+00, -1.7791e+00,\n",
      "         -7.9428e-01, -7.9338e-01, -1.1346e-01,  1.6743e+00, -1.2022e+00,\n",
      "         -2.5470e-01,  1.8694e+00,  6.1505e-01,  5.5765e-01, -2.1263e+00,\n",
      "         -9.1687e-01,  2.1327e+00, -8.3846e-01, -1.3316e+00, -4.0488e-01,\n",
      "          1.8704e-01, -5.0679e-01, -1.7195e-02,  2.3790e-01, -1.0971e+00,\n",
      "         -2.4353e+00, -5.9291e-01, -8.4307e-01,  2.2893e-01,  1.6879e+00,\n",
      "         -3.4583e-01, -4.1095e-01,  3.5481e-01, -3.5193e-01,  3.6739e-01,\n",
      "         -3.0969e-01,  9.7442e-01, -4.4820e-01,  3.1823e-01, -8.7039e-02,\n",
      "         -1.4081e+00, -3.0440e-01,  1.3651e+00, -1.9011e-01, -8.6938e-01],\n",
      "        [ 9.5590e-01, -3.1076e-01, -1.3843e+00, -1.0597e+00, -1.3799e-01,\n",
      "         -2.3876e+00, -1.5701e+00,  9.6096e-03,  1.3829e+00,  6.0881e-01,\n",
      "         -5.0429e-01, -1.9037e-01,  1.1184e+00, -4.3052e-01,  3.4052e-01,\n",
      "          6.5771e-02,  9.9316e-02, -1.4842e+00, -1.7203e+00,  1.8687e-01,\n",
      "         -1.6586e+00, -4.5098e-01, -9.5811e-02,  1.3449e-01, -6.6218e-01,\n",
      "          6.0973e-01,  8.6498e-01, -5.6404e-02,  1.1956e+00,  5.6744e-01,\n",
      "         -6.4945e-01, -2.2824e+00, -1.4953e-01,  1.7964e-01,  2.1202e+00,\n",
      "         -1.8476e+00,  6.4566e-01, -1.6180e+00, -9.6687e-01, -1.3799e+00,\n",
      "          1.0805e+00,  2.1617e+00,  2.7226e-01,  2.3839e+00,  1.1556e+00,\n",
      "         -4.2812e-01,  1.3745e+00,  6.4918e-01,  1.9522e-01, -6.4685e-01,\n",
      "          3.9399e-01,  2.5454e-01, -1.1125e+00,  1.6672e+00,  2.4979e-01,\n",
      "         -1.7042e+00,  6.3695e-02,  2.0809e-01,  1.4219e+00, -1.7888e-01,\n",
      "          5.5152e-01, -3.6747e-01, -6.4456e-01,  5.2193e-01, -5.0143e-01,\n",
      "          8.1064e-01,  1.9712e-01,  4.8574e-01,  8.9521e-01,  1.2630e-01,\n",
      "         -6.7111e-01,  8.8927e-01,  2.0301e-01,  1.1918e+00, -1.1883e-01,\n",
      "         -1.3915e+00,  9.3558e-01, -2.3852e+00, -1.6876e-01, -1.5090e+00,\n",
      "          1.0157e+00, -3.2723e-03, -4.5275e-01,  3.5852e-01, -5.8705e-01,\n",
      "         -1.3634e+00, -1.8719e-02,  8.2830e-02,  1.6891e+00, -4.1734e-01,\n",
      "          1.1332e-01, -1.4587e+00, -4.0179e-01,  1.2223e+00,  2.4872e+00,\n",
      "         -2.1602e+00, -4.9217e-01,  1.1173e-01, -1.2314e+00,  7.8269e-01]])\n",
      "tensor([54, 94])\n"
     ]
    }
   ],
   "source": [
    "a = torch.randn((2,1,1,100))\n",
    "b = a.reshape(2,100)\n",
    "print(b)\n",
    "c = b.argmax(dim=-1)\n",
    "print(c)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-06-15T17:29:02.124993Z",
     "start_time": "2024-06-15T17:29:02.116640300Z"
    }
   },
   "id": "5e82b574e3d6425e",
   "execution_count": 20
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[False]]])\n",
      "3.0\n"
     ]
    }
   ],
   "source": [
    "a = torch.ones((1,1,1))*3\n",
    "b = a==1\n",
    "print(b)\n",
    "if b:\n",
    "    print('ah')\n",
    "print(a.item())"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-06-15T17:34:41.958736Z",
     "start_time": "2024-06-15T17:34:41.952959900Z"
    }
   },
   "id": "efd38439b50f6ba",
   "execution_count": 27
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "e4a05288d673e743"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
